package leetcode.editor.cn;

import java.util.PriorityQueue;

/**
 * @author: yangwk
 * @date: 2022/12/28
 * @description:
 **/
public class P452 {
    public static void main(String[] args) {
//        int[][] arr = {{10, 16}, {2, 8}, {1, 6}, {7, 12}};
        int[][] arr = {{-2147483646, -2147483645}, {2147483646, 2147483647}};
        System.out.println(findMinArrowShots(arr));
    }

    public static int findMinArrowShots(int[][] points) {
        PriorityQueue<int[]> priorityQueue = new PriorityQueue<>((o1, o2) -> {
            long right = (long) o1[1] - (long) o2[1];
            long left = (long) o1[0] - (long) o2[0];
            if (right == 0) {
                return left > 0 ? 1 : -1;
            }
            return right > 0 ? 1 : -1;
        });
        for (int[] point : points) {
            priorityQueue.offer(point);
        }
        int count = 0;
        while (priorityQueue.size() > 1) {
            int[] first = priorityQueue.poll();
            int[] second = priorityQueue.poll();
            int right = first[1];
            int left = second[0];
            if (right >= left) {
                count++;
                int[] newArr = new int[]{left, right};
                priorityQueue.offer(newArr);
            } else {
                priorityQueue.offer(second);
            }
        }
        return points.length - count;
    }
}
